import numpy as np
import matplotlib.pyplot as plt

def radar_chart():
    # 设置中文字体
    plt.rcParams["font.family"] = ["SimHei", "WenQuanYi Micro Hei", "Heiti TC"]

    # 数据
    categories = ['战略地位', '技术难度', '开发成本', '市场潜力', '预期收益']
    projects = {
        '项目A': [8, 6, 5, 7, 9],
        '项目B': [9, 8, 7, 6, 7],
        '项目C': [5, 3, 4, 8, 6],
        '项目D': [6, 4, 3, 5, 8]
    }

    # 负向指标取反（技术难度、开发成本）
    for project in projects.values():
        project[1] = 10 - project[1]  # 技术难度取反
        project[2] = 10 - project[2]  # 开发成本取反

    # 计算角度
    num_vars = len(categories)
    angles = np.linspace(0, 2*np.pi, num_vars, endpoint=False).tolist()
    angles += angles[:1]  # 闭合图形

    # 创建雷达图
    fig, ax = plt.subplots(figsize=(8, 8), subplot_kw=dict(polar=True))

    # 绘制每个项目
    colors = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728']
    for i, (name, values) in enumerate(projects.items()):
        values += values[:1]  # 闭合数值
        ax.plot(angles, values, 'o-', linewidth=2, label=name, color=colors[i])
        ax.fill(angles, values, alpha=0.1, color=colors[i])

    # 设置坐标轴
    ax.set_thetagrids(np.degrees(angles[:-1]), categories, fontsize=12)
    ax.set_ylim(0, 10)
    ax.set_rlabel_position(0)  # 角度标签位置

    # 添加标题和图例
    ax.set_title('项目综合评估雷达图', fontsize=16, y=1.05)
    plt.legend(loc='upper right', bbox_to_anchor=(1.3, 1.1))

    plt.show()

if __name__ == '__main__':
    data = [8, 6, 5, 7, 9]
    radar_chart()